﻿Imports DTO
Imports System.Data.OleDb

Public Class ThamSoDAO
    Public Function LaySoLuongNhapToiThieu() As Double
        Dim connection As OleDbConnection = DataProvider.ConnectDB()
        Dim sql As String = "select SoLuongNhapToiThieu from THAMSO"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, connection)
        Dim kq As Double = cmd.ExecuteScalar()
        connection.Close()
        Return kq
    End Function
    Public Function LaySoLuongTonToiDa() As Double
        Dim connection As OleDbConnection = DataProvider.ConnectDB()
        Dim sql As String = "select SoLuongTonToiDa from THAMSO"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, connection)
        Dim kq As Double = cmd.ExecuteScalar()
        connection.Close()
        Return kq
    End Function
    Public Function LaySoLuongTonToiThieu() As Double
        Dim connection As OleDbConnection = DataProvider.ConnectDB()
        Dim sql As String = "select SoLuongTonToiThieu from THAMSO"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, connection)
        Dim kq As Double = cmd.ExecuteScalar()
        connection.Close()
        Return kq
    End Function
    Public Function SoTienNoToiDa_KhachHang() As Double
        Dim connection As OleDbConnection = DataProvider.ConnectDB()
        Dim sql As String = "select SoTienNoToiDa_KhachHang from THAMSO"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, connection)
        Dim kq As Double = cmd.ExecuteScalar()
        connection.Close()
        Return kq
    End Function
    ' Lay toan bo bang tham so 
    Public Shared Function LayToanBoKhachHang() As BangThamSoDTO

        Dim connect As OleDbConnection = DataProvider.ConnectDB()
        Dim sql As String = "select * From THAMSO"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, connect)
        Dim reader As OleDbDataReader = cmd.ExecuteReader()
        Dim ThamSo As BangThamSoDTO = New BangThamSoDTO()
        While reader.Read
            ThamSo.SoLuongNhapToiThieu = reader.GetInt32(0)
            ThamSo.SoLuongTonToiDa = reader.GetInt32(1)
            ThamSo.SoLuongTonToiThieu = reader.GetInt32(2)
            ThamSo.SoTienNoToiDa_KhachHang = reader.GetDouble(3)

        End While
        connect.Close()
        Return ThamSo
    End Function
    ' Cap nhat lai bang tham so
    Public Shared Function CapNhatLaiBangThamSo(ByVal ThamSo As BangThamSoDTO) As Double
        Dim kq As Double
        Dim connect As OleDbConnection = DataProvider.ConnectDB()
        Dim sql As String = "Update THAMSO set SoLuongNhapToiThieu=? , SoLuongTonToiDa =?  ,SoLuongTonToiThieu= ? ,  SoTienNoToiDaKhachHang = ? "
        Dim cmd As OleDbCommand = New OleDbCommand(sql, connect)
        cmd.Parameters.Add("@SoLuongNhapToiThieu", OleDbType.Integer)
        cmd.Parameters("@SoLuongNhapToiThieu").Value = ThamSo.SoLuongNhapToiThieu

        cmd.Parameters.Add("@SoLuongTonToiDa", OleDbType.Integer)
        cmd.Parameters("@SoLuongTonToiDa").Value = ThamSo.SoLuongTonToiDa

        cmd.Parameters.Add("@SoLuongTonToiThieu", OleDbType.Integer)
        cmd.Parameters("@SoLuongTonToiThieu").Value = ThamSo.SoLuongTonToiThieu

        cmd.Parameters.Add("@SoTienNoToiDaKhachHang", OleDbType.Double)
        cmd.Parameters("@SoTienNoToiDaKhachHang").Value = ThamSo.SoTienNoToiDa_KhachHang


        kq = cmd.ExecuteNonQuery()
        connect.Close()
        Return kq

    End Function
End Class
